﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace Model
{
    public  class Common
    {
        /// <summary>
        /// 判断时间字段是否为空
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public static bool IsDateNull(DateTime? dt)
        {
            if (dt == null || dt == DateTime.MinValue)
            {
                return true;
            }
            return false;
        }
        public static string AdminLoginSessionKey = "AdminLoginSessionKey";
        public static string DeliveryLoginSessionKey = "DeliveryLoginSessionKey";
        public static string UserLoginSessionKey = "UserLoginSessionKey";
        public static string SUCCESS = ResultStatusEnum.T.ToString();
        public static string FAIL = ResultStatusEnum.F.ToString();

        public static T DeepCopy<T>(T obj)
        {
            //如果是字符串或值类型则直接返回
            if (obj is string || obj.GetType().IsValueType) return obj;

            object retval = Activator.CreateInstance(obj.GetType());
            FieldInfo[] fields = obj.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
            foreach (FieldInfo field in fields)
            {
                try { field.SetValue(retval, DeepCopy(field.GetValue(obj))); }
                catch { }
            }
            return (T)retval;
        }
    }
}
